package com.example.presenters;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.widget.Button;

import com.example.model.ItemList;
import com.example.interfaces.IProfileActivity;
import com.example.model.Item;
import com.example.model.User;
import com.example.model.UserList;

/**
 * This class will handle the profile activity, and switch between presenters as
 * need for user actions.
 * 
 * @author 3Factorial
 */
public class ProfilePresenter {

	private IProfileActivity pro;
	private UserList users;

	/**
	 * Instantiates the ProfilePresenter
	 * 
	 * @param pro
	 *            The profile activity.
	 * @param users
	 *            The user list.
	 * @param itemList
	 */
	public ProfilePresenter(IProfileActivity pro, UserList users) {
		this.pro = pro;
		this.users = users;
	}

	/**
	 * Finds a user.
	 * 
	 * @param username
	 *            User name to search for.
	 * @return The User
	 */
	public User findUser(String username) {
		return users.getUserByUsername(username);
	}

	/**
	 * Gets a list of the items' names in the ItemList in an array.
	 * 
	 * @return A list of the items' names in the ItemList in an array.
	 */
	public String[] getItemList(String currUserName) {
		User u = findUser(currUserName);
		String[] list = new String[u.getItems().size()];
		for (int i = 0; i < u.getItems().size(); i++) {
			list[i] = u.getItems().get(i).getItemName();
		}
		return list;
	}

	// TODO I don't know if this is supposed to go here
	// Fine here - Armo
	/**
	 * Hides the admin button for regular users.
	 * 
	 * @param adminButton
	 *            The admin button to hide.
	 * @param currUserName
	 *            The current user's name for this event.
	 */
	public void hideAdminButton(Button adminButton, String currUserName) {
		User u = findUser(currUserName);
		if (!u.isAdmin()) {
			adminButton.setVisibility(View.GONE);
		}
	}

	/**
	 * Creates a list of all lost items this user has created.
	 * 
	 * @param currUserName
	 *            Current user's name.
	 * @return All the lost items this user has created.
	 */
	public String[] getLostItemList(String currUserName) {
		User u = findUser(currUserName);
		String[] list = new String[u.getLostItems().size()];
		ArrayList<Item> lostItems = u.getLostItems();
		for (int i = 0; i < u.getLostItems().size(); i++) {
			list[i] = lostItems.get(i).getItemName();
		}
		return list;
	}

	/**
	 * Creates a list of all found items this user has created.
	 * 
	 * @param currUserName
	 *            Current user's name.
	 * @return All the found items this user has created.
	 */
	public String[] getFoundItemList(String currUserName) {
		User u = findUser(currUserName);
		String[] list = new String[u.getFoundItems().size()];
		ArrayList<Item> foundItems = u.getFoundItems();
		for (int i = 0; i < u.getFoundItems().size(); i++) {
			list[i] = foundItems.get(i).getItemName();
		}
		return list;
	}

}
